
import java.io.IOException;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.LayerManager;
import javax.microedition.lcdui.game.Sprite;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author khang
 */

// FireBalls = hit-head
//bomb = hit-left-foot
//bullet2 = hit-right-foot
public class myPlayer {
    private Sprite theCat,death;    
    private int iwidth,iheight;
    private LayerManager lm;
    private Sound sound;
    int coolDown;
    int numHitHead;
    public myPlayer(LayerManager _lm,Sound s,int width,int height){
        try {
        	lm=_lm;
        	
            iwidth=width;
            iheight=height;
            numHitHead=0;
            
            death=new Sprite(Image.createImage("/DevildomTorchOrrerriesSun.png"), 32, 32);
            death.setFrame(2);
            death.defineReferencePixel(death.getWidth()/2, death.getHeight()/2);
            death.setVisible(false);
            lm.append(death);
            
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    
    public void enableBigFart()
    {
    	try
    	{
    		coolDown=18;
	    	theCat=new Sprite(Image.createImage("/cat_fart.jpg"), 120, 200);
	    	int[] seq= {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17};
	    	theCat.setFrameSequence(seq);
	    	theCat.setPosition(60, 100);
	    	theCat.setVisible(true);
	    	lm.append(theCat);
    	} catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    
    public void enableHitLeftFoot()
    {
    	try
    	{
    		coolDown=9;
	    	theCat=new Sprite(Image.createImage("/hit-left-foot.jpg"), 120, 200);
	    	int[] seq= {0,1,2,3,4,5,6,7,8};
	    	theCat.setFrameSequence(seq);
	    	theCat.setPosition(60, 100);
	    	theCat.setVisible(true);
	    	lm.append(theCat);
    	} catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    
    public void enableHitRightFoot()
    {
    	try
    	{
    		coolDown=9;
	    	theCat=new Sprite(Image.createImage("/hit-right-foot.jpg"), 120, 200);
	    	int[] seq= {0,1,2,3,4,5,6,7,8};
	    	theCat.setFrameSequence(seq);
	    	theCat.setPosition(60, 100);
	    	theCat.setVisible(true);
	    	lm.append(theCat);
    	} catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    
    public int enableHitHead()
    {
    	try
    	{
    		numHitHead++;
    		coolDown=6;
	    	theCat=new Sprite(Image.createImage("/hit-head.jpg"), 120, 200);
	    	int[] seq= {0,1,2,3,4,5};
	    	theCat.setFrameSequence(seq);
	    	theCat.setPosition(60, 100);
	    	theCat.setVisible(true);
	    	lm.append(theCat);
	    	//for(int i=0;i<6;i++)
	    	//	theCat.nextFrame();
    	} catch (IOException ex) {
            ex.printStackTrace();
        }
    	return numHitHead;
    }
    
    public void enableHitStomach()
    {
    	try
    	{
    		coolDown=5;
	    	theCat=new Sprite(Image.createImage("/hit-stomach.jpg"), 120, 200);
	    	int[] seq= {0,1,2,3,4};
	    	theCat.setFrameSequence(seq);
	    	theCat.setPosition(60, 100);
	    	theCat.setVisible(true);
	    	lm.append(theCat);
    	} catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    
    public void enableIdle()
    {
    	try
    	{
    		coolDown=-1;
	    	theCat=new Sprite(Image.createImage("/idle.jpg"), 120, 200);
	    	int[] seq= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
	    	theCat.setFrameSequence(seq);
	    	theCat.setPosition(60, 100);
	    	theCat.setVisible(true);
	    	lm.append(theCat);
    	} catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    
    public void enableKnockOut()
    {
    	try
    	{
    		numHitHead=0;
    		coolDown=18;
	    	theCat=new Sprite(Image.createImage("/knockout.jpg"), 120, 200);
	    	int[] seq= {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17};
	    	theCat.setFrameSequence(seq);
	    	theCat.setPosition(60, 100);
	    	theCat.setVisible(true);
	    	lm.append(theCat);
    	} catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    
    
    public void disableCat()
    {
    	lm.remove(theCat);
    }
    public int CatMove(){
    	if(coolDown>0)
    		coolDown--;
    	theCat.nextFrame();
    	return coolDown;
    }
    
    
}
